﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Internet_Deliver_Therapy.Controllers;
using Internet_Deliver_Therapy.Models;

namespace Internet_Deliver_Therapy.Views.Admin
{
    public partial class RegisterPsychologist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Ensure that user login before being able to access the secure pages
            if (Session["Email"] != null)
            {
                string loginUserEmail = Session["Email"].ToString();

                UsersController userController = new UsersController();
                //string loginUserFirstName = userController.getUserFirstName(loginUserEmail);
                //lblUserFirstName.Text = loginUserFirstName;
            }
            else
            {
                Response.Redirect("~/Views/Index/Login.aspx");
            }

            if (!IsPostBack)
            {
                ddlGender.Items.Add("Male");
                ddlGender.Items.Add("Female");
            }
        }
        protected void Register_Click(object sender, EventArgs e)
        {
            //Send a random password to the Psychiatrist via email, which can be changed later on
            //Create a new psychologist user
            string nric = tbNRIC.Text.ToString();
            string firstName = tbFirstName.Text.ToString();
            string lastName = tbLastName.Text.ToString();
            string race = tbRace.Text.ToString();
            string email = tbEmail.Text.ToString();
            string mobileNo = tbMobileNo.Text.ToString();
            string officeNo = tbOfficeNo.Text.ToString();
            string designation = tbDesignation.Text.ToString();
            string gender_string = ddlGender.Text.ToString();

            string day_string = Request.Form["daydropdown"].ToString();
            string mth_string = Request.Form["monthdropdown"].ToString();
            string year_string = Request.Form["yeardropdown"].ToString();

            int day_int = Int32.Parse(day_string);
            int mth_int = Int32.Parse(mth_string);
            int year_int = Int32.Parse(year_string);

            DateTime dob = new DateTime(year_int, mth_int, day_int);

            char gender = gender_string[0];

            string day_string2 = Request.Form["daydropdown2"].ToString();
            string mth_string2 = Request.Form["monthdropdown2"].ToString();
            string year_string2 = Request.Form["yeardropdown2"].ToString();

            int day_int2 = Int32.Parse(day_string);
            int mth_int2 = Int32.Parse(mth_string);
            int year_int2 = Int32.Parse(year_string);

            DateTime employmentDate = new DateTime(year_int, mth_int, day_int);

            Users user = new Users(nric, firstName, lastName, race, email, "Psychologist", designation, mobileNo, officeNo, gender, dob, employmentDate);

            UsersController userController = new UsersController();
            bool registered = userController.createUsers(user);
            if (registered == true)
            {
                Session["NRIC"] = nric;
                Response.Redirect("~/Views/Admin/Psychologist/PsychologistsManagement.aspx");
            }
            else
            {
                ErrorMessage.Text = "There seems to be some problem with registering";
            }
        }
    }
}